package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUIPageDAO;
import com.ourteam.product.ui.dao.ProductUIPage;
import com.ourteam.product.ui.dao.ProductUIPageDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:20 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUIPageDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUIPageDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        DomainId,
        PageTemplateId,
        PageCode,
        PageName,
        Status,
        Remarks,
        DomainCode,
        DomainName,
        TemplateName
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.DomainId,
        _DataObjectProperty.PageTemplateId,
        _DataObjectProperty.PageCode,
        _DataObjectProperty.PageName,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.DomainCode,
        _DataObjectProperty.DomainName,
        _DataObjectProperty.TemplateName
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUIPage, ProductUIPageDAOQueryBean> daoHelper;

  public AbstractProductUIPageDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<ProductUIPage, ProductUIPageDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName)
          .append(" RELATED_P8N41Y_ProductUIDomain ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIDomainDAO.Id,
              com.ourteam.product.ui.dao.IProductUIDomainDAO.EntityName + ".",
              "RELATED_P8N41Y_ProductUIDomain."));
      relatedJoinSQLBuffer.append(" = ").append(DomainId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIPageTemplateDAO.EntityName)
          .append(" RELATED_WJ3B6Z_ProductUIPageTemplate ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIPageTemplateDAO.Id,
              com.ourteam.product.ui.dao.IProductUIPageTemplateDAO.EntityName + ".",
              "RELATED_WJ3B6Z_ProductUIPageTemplate."));
      relatedJoinSQLBuffer.append(" = ").append(PageTemplateId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUIPage
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUIPage aProductUIPage) throws Exception {

    if (aProductUIPage == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUIPage.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUIPage
   * @throws Exception
   */
  public void insert(ProductUIPage aProductUIPage) throws Exception {

    super.doInsert(aProductUIPage);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUIPage
   * @throws Exception
   */
  public void batchInsert(ProductUIPage[] aProductUIPages) throws Exception {

    super.doBatchInsert(aProductUIPages);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUIPageDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUIPage aProductUIPage) throws Exception {

    delete(aProductUIPage.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUIPage
   * @throws Exception
   */
  public void update(ProductUIPage aProductUIPage) throws Exception {

    if (aProductUIPage.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUIPage);

    ProductUIPage tempObj = findById(aProductUIPage.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUIPage, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUIPages[]
   * @throws Exception
   */
  public void batchUpdate(ProductUIPage[] aProductUIPages) throws Exception {

    super.doBatchUpdate(aProductUIPages);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUIPage
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(ProductUIPage aProductUIPage, ProductUIPageDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aProductUIPage, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUIPageDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUIPage aProductUIPage) throws Exception {}

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUIPage findById(final long id) throws Exception {

    ProductUIPageDAOQueryBean queryBean = new ProductUIPageDAOQueryBean();

    ProductUIPageDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUIPage[] ProductUIPages = query(queryBean);

    if (ProductUIPages.length == 0) {
      return null;
    } else {
      return ProductUIPages[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUIPage[]
   * @throws Exception
   */
  public ProductUIPage[] query(ProductUIPageDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUIPageRowMapper());

    return (ProductUIPage[]) result.toArray(new ProductUIPage[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUIPageDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUIPageDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(ProductUIPage[] aProductUIPages, ProductUIPageDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUIPages, queryBean);
  }

  public void synchronize(
      ProductUIPage[] aProductUIPages,
      ProductUIPageDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUIPage> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUIPages, queryBean, callBack);
  }

  public static class JdbcProductUIPageRowMapper implements RowMapper<ProductUIPage> {

    public ProductUIPage mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUIPage object = new ProductUIPage();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object domainId = null;

        domainId = resultSet.getObject(columnIndex++);

        object.setDomainIdNull(resultSet.getBoolean(columnIndex++));

        if (domainId != null) {

          setBeanValue(object, _DataObjectProperty.DomainId, domainId);
        }

        Object pageTemplateId = null;

        pageTemplateId = resultSet.getObject(columnIndex++);

        object.setPageTemplateIdNull(resultSet.getBoolean(columnIndex++));

        if (pageTemplateId != null) {

          setBeanValue(object, _DataObjectProperty.PageTemplateId, pageTemplateId);
        }

        Object pageCode = null;

        pageCode = resultSet.getObject(columnIndex++);

        object.setPageCodeNull(resultSet.getBoolean(columnIndex++));

        if (pageCode != null) {

          setBeanValue(object, _DataObjectProperty.PageCode, pageCode);
        }

        Object pageName = null;

        pageName = resultSet.getObject(columnIndex++);

        object.setPageNameNull(resultSet.getBoolean(columnIndex++));

        if (pageName != null) {

          setBeanValue(object, _DataObjectProperty.PageName, pageName);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object domainCode = null;

        domainCode = resultSet.getObject(columnIndex++);

        object.setDomainCodeNull(resultSet.getBoolean(columnIndex++));

        if (domainCode != null) {

          setBeanValue(object, _DataObjectProperty.DomainCode, domainCode);
        }

        Object domainName = null;

        domainName = resultSet.getObject(columnIndex++);

        object.setDomainNameNull(resultSet.getBoolean(columnIndex++));

        if (domainName != null) {

          setBeanValue(object, _DataObjectProperty.DomainName, domainName);
        }

        Object templateName = null;

        templateName = resultSet.getObject(columnIndex++);

        object.setTemplateNameNull(resultSet.getBoolean(columnIndex++));

        if (templateName != null) {

          setBeanValue(object, _DataObjectProperty.TemplateName, templateName);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
